﻿
package com.STS.ELearning.Captivate.helpers
{
	import flash.events.Event;
	import flash.events.IEventDispatcher;
	import com.STS.ELearning.Captivate.QuizData;
	import com.STS.ELearning.Captivate.events.QuestionWidgetEvent;
	import com.STS.ELearning.Captivate.events.WidgetEvent;
	public class CaptivateEventsToWidgetEvents
	{
		
		private static const CP_SLIDE_ENTER_EVENT:String = "CPSlideEnterEvent";
		private static const CP_SLIDE_EXIT_EVENT:String = "CPSlideExitEvent";
		private static const CP_MOVIE_PAUSE_EVENT:String = "CPMoviePauseEvent";
		private static const CP_MOVIE_RESUME_EVENT:String = "CPMovieResumeEvent";
		private static const CP_MOVIE_START_EVENT:String = "CPMovieStartEvent";
		private static const CP_MOVIE_STOP_EVENT:String = "CPMovieStopEvent";
		private static const CP_INTERACTIVE_ITEM_SUBMIT_EVENT:String = "CPInteractiveItemSubmitEvent";
		private static const CP_QUESTION_SUBMIT_EVENT:String = "CPQuestionSubmitEvent";
		
		private static var listener:IEventDispatcher;
		private static var dispatcher:IEventDispatcher;
		
		public function CaptivateEventsToWidgetEvents(lock:StaticLock) 
		{
		}
		
		public static function registerEventsWithWidgetEvent (_listener:IEventDispatcher, _dispatcher:IEventDispatcher):void {
			
			listener = _listener;
			dispatcher = _dispatcher;
			
			
			listener.addEventListener(CP_SLIDE_ENTER_EVENT, triggerSlideEnterEvent);
			listener.addEventListener(CP_SLIDE_EXIT_EVENT, triggerSlideExitEvent);
			
			
			listener.addEventListener(CP_MOVIE_PAUSE_EVENT, triggerPauseEvent);
			listener.addEventListener(CP_MOVIE_RESUME_EVENT, triggerResumeEvent);
			
			
			listener.addEventListener(CP_MOVIE_STOP_EVENT, triggerStopEvent);
			
			
			listener.addEventListener(CP_INTERACTIVE_ITEM_SUBMIT_EVENT, triggerInteractiveSubmitEvent);
			listener.addEventListener(CP_QUESTION_SUBMIT_EVENT, triggerQuestionSubmitEvent);
			
		}
		
		
		static private function triggerQuestionSubmitEvent(e:Object):void 
		{
			dispatcher.dispatchEvent(new QuestionWidgetEvent(QuestionWidgetEvent.QUESTION_SUBMITTED,null,null,null,null,false,false,new QuizData(e.questionEventData)));
		}
		
		static private function triggerInteractiveSubmitEvent(e:Object):void 
		{
			dispatcher.dispatchEvent(new WidgetEvent(WidgetEvent.INTERACTIVE_ITEM_SUBMITTED,false,false,Number(e.frameNumber),Number(e.slideNumber), null, false, new QuizData(e.questionEventData)));
		}
		
		static private function triggerStopEvent(e:Object):void 
		{
			dispatcher.dispatchEvent(new WidgetEvent(WidgetEvent.MOVIE_ENDED));
		}
		
		static private function triggerResumeEvent(e:Object):void
		{
			dispatcher.dispatchEvent(new WidgetEvent(WidgetEvent.RESUME,false,false,Number(e.frameNumber),Number(e.slideNumber),null,Boolean(e.userPlay)));
		}
		
		static private function triggerPauseEvent (e:Object):void
		{
			dispatcher.dispatchEvent(new WidgetEvent(WidgetEvent.PAUSE,false,false,Number(e.frameNumber),Number(e.slideNumber),null,Boolean(e.userPause)));
		}
		
		static private function triggerSlideExitEvent (e:Object):void
		{
			dispatcher.dispatchEvent(new WidgetEvent(WidgetEvent.EXIT_SLIDE,false,false,Number(e.frameNumber),Number(e.slideNumber),String(e.slideLabel)));
		}
		
		static private function triggerSlideEnterEvent (e:Object):void
		{
			dispatcher.dispatchEvent(new WidgetEvent(WidgetEvent.ENTER_SLIDE,false,false,Number(e.frameNumber),Number(e.slideNumber),String(e.slideLabel)));
		}
		
	}
}
class StaticLock{}